package com.example.monitordemo.constant;

import static com.example.monitordemo.config.MonitorConfig.LINUX_INSTANCE;

public interface LinuxConstant {
    
    

    /**
     * 运行时间
     */
    String RUN_TIME = "avg(time() - node_boot_time_seconds{instance=~\""+ LINUX_INSTANCE +"\"})";

    /**
     * 总内存
     */
    String SUM_MEMORY = "sum(node_memory_MemTotal_bytes{instance=~\""+ LINUX_INSTANCE +"\"})";

    /**
     * CPU核数
     */
    String CPU_NUM = "count(node_cpu_seconds_total{instance=~\""+ LINUX_INSTANCE +"\", mode='system'})";

    /**
     * CPU等待IO时间
     */
    String CPU_IOWAIT = "avg(irate(node_cpu_seconds_total{instance=~\""+ LINUX_INSTANCE +"\",mode=\"iowait\"}[5m])) * 100";

    /**
     * 总CPU使用率
     */
    String CPU_USE_RATE = "avg(irate(node_cpu_seconds_total{instance=~\""+ LINUX_INSTANCE +"\",mode=~\"sytem|user|iowait|irq|softirq|nice|steal|guest\"}[5m])) * 100";

    /**
     * 内存使用率
     */
    String MEMORY_USE_RATE = "(1 - (node_memory_MemAvailable_bytes{instance=~\""+ LINUX_INSTANCE +"\"} / (node_memory_MemTotal_bytes{instance=~\""+ LINUX_INSTANCE +"\"})))* 100";

    /**
     * 交换分区使用率
     */
    String SWAP = "(1 - ((node_memory_SwapFree_bytes{instance=~\""+ LINUX_INSTANCE +"\"})/ (node_memory_SwapTotal_bytes{instance=~\""+ LINUX_INSTANCE +"\"}))) * 100";

    /**
     * 各分区总空间(EXT.*&#x2F;XFS)
     */
    String EACH_DISK_TOTAL_SPACE = "node_filesystem_size_bytes{instance=~'"+ LINUX_INSTANCE +"',fstype=~\"ext.*|xfs\",mountpoint !~\".*pod.*\"}-0";

    /**
     * 各分区可用空间
     */
    String EACH_DISK_FREE_SPACE = "node_filesystem_avail_bytes{instance=~'"+ LINUX_INSTANCE +"',fstype=~\"ext.*|xfs\",mountpoint !~\".*pod.*\"}-0";

    /**
     * 各分区节点数
     */
    String EACH_DISK_NODE_NUM = "node_filesystem_files{instance=~'"+ LINUX_INSTANCE +"',fstype=~\"ext.*|xfs\",mountpoint !~\".*pod.*\"}-0";

    /**
     * 各分区可用节点数
     */
    String EACH_DISK_FREE_NODE_NUM = "node_filesystem_files_free{instance=~'"+ LINUX_INSTANCE +"',fstype=~\"ext.*|xfs\",mountpoint !~\".*pod.*\"}-0";

    /**
     * 各分区节点使用率
     */
    String EACH_DISK_NODE_USE_RATE = "(node_filesystem_files{instance=~'"+ LINUX_INSTANCE +"',fstype=~\"ext.*|xfs\",mountpoint !~\".*pod.*\"}-node_filesystem_files_free{instance=~'"+ LINUX_INSTANCE +"',fstype=~\"ext.*|xfs\",mountpoint !~\".*pod.*\"}) *100/node_filesystem_files {instance=~'"+ LINUX_INSTANCE +"',fstype=~\"ext.*|xfs\",mountpoint !~\".*pod.*\"}";

    /**
     * 每小时流量下载eth0网卡
     */
    String HOUR_NET_RECEIVED = "increase(node_network_receive_bytes_total{instance=~\""+ LINUX_INSTANCE +"\",device=~\"eth0\"}[60m])";

    /**
     * 每小时流量上传eth0网卡
     */
    String HOUR_NET_SENT = "increase(node_network_transmit_bytes_total{instance=~\""+ LINUX_INSTANCE +"\",device=~\"eth0\"}[60m])";

    /**
     * CPU系统使用率
     */
    String CPU_SYSTEM_USE_RATE = "avg(irate(node_cpu_seconds_total{instance=~\""+ LINUX_INSTANCE +"\",mode=\"system\"}[5m])) by (instance) *100";

    /**
     * CPU用户使用率
     */
    String CPU_USER_USE_RATE = "avg(irate(node_cpu_seconds_total{instance=~\""+ LINUX_INSTANCE +"\",mode=\"user\"}[5m])) by (instance) *100";

    /**
     * CPU磁盘使用率
     */
    String CPU_DISK_USE_RATE = "avg(irate(node_cpu_seconds_total{instance=~\""+ LINUX_INSTANCE +"\",mode=\"iowait\"}[5m])) by (instance) *100";

    /**
     * CPU总使用率
     */
    String CPU_SUM_USE_RATE = "avg by (instance)(irate(node_cpu_seconds_total{instance=~\""+ LINUX_INSTANCE +"\",mode=~\"sytem|user|iowait|irq|softirq|nice|steal|guest\"}[5m])) *100";

    /**
     * 单个实例总内存
     */
    String INSTANCE_SUM_MEMORY = "node_memory_MemTotal_bytes{instance=~\""+ LINUX_INSTANCE +"\"}";

    /**
     * 已用内存
     */
    String USED_MEMORY = "node_memory_MemTotal_bytes{instance=~\""+ LINUX_INSTANCE +"\"} - node_memory_MemAvailable_bytes{instance=~\""+ LINUX_INSTANCE +"\"}";

    /**
     * 剩余内存
     */
    String INSTANCE_FREE_MEMORY = "node_memory_MemAvailable_bytes{instance=~\""+ LINUX_INSTANCE +"\"}";

    /**
     * 实例已用内存
     */
    String INSTANCE_USED_MEMORY = "node_memory_MemTotal_bytes{instance=~\""+ LINUX_INSTANCE +"\"} - (node_memory_Cached_bytes{instance=~\""+ LINUX_INSTANCE +"\"} - node_memory_Buffers_bytes{instance=~\""+ LINUX_INSTANCE +"\"} - node_memory_MemFree_bytes{instance=~\""+ LINUX_INSTANCE +"\"})";

    /**
     * 每秒宽带接收ens33
     */
    String SECOND_NET_RECEIVED = "irate(node_network_receive_bytes_total{instance=~'"+ LINUX_INSTANCE +"',device=~\"eth0\"}[5m])*8";

    /**
     * 每秒宽带发送ens33
     */
    String SECOND_NET_SENT = "irate(node_network_transmit_bytes_total{instance=~'"+ LINUX_INSTANCE +"',device=~\"eth0\"}[5m])*8";

    /**
     * 系统1分钟负载
     */
    String SYSTEM_1MINUTE_LOAD = "node_load1{instance=~\""+ LINUX_INSTANCE +"\"}";

    /**
     * 系统5分钟负载
     */
    String SYSTEM_5MINUTES_LOAD = "node_load5{instance=~\""+ LINUX_INSTANCE +"\"}";

    /**
     * 系统15分钟负载
     */
    String SYSTEM_15MINUTES_LOAD = "node_load15{instance=~\""+ LINUX_INSTANCE +"\"}";

    /**
     * 系统CPU总核数
     */
    String SYSTEM_CPU_NUM = "sum(count(node_cpu_seconds_total{instance=~\""+ LINUX_INSTANCE +"\", mode='system'}) by (cpu,instance)) by(instance)";

    /**
     * 磁盘每秒读
     */
    String DISK_SECOND_READ = "irate(node_disk_read_bytes_total{instance=~\""+ LINUX_INSTANCE +"\"}[5m])";

    /**
     * 磁盘每秒写
     */
    String DISK_SECOND_WRITE = "irate(node_disk_written_bytes_total{instance=~\""+ LINUX_INSTANCE +"\"}[5m])";

    /**
     * 磁盘使用率
     */
    String DISK_USE_RATE =
            "(" +
                "node_filesystem_size_bytes{" +
                    "instance=~\""+ LINUX_INSTANCE +"\"," +
                    "fstype=~\"ext.*|xfs\"," +
                    "mountpoint !~\".*pod.*\"" +
                "}" +
                "-" +
                "node_filesystem_free_bytes{" +
                    "instance=~\""+ LINUX_INSTANCE +"\"," +
                    "fstype=~\"ext.*|xfs\"," +
                    "mountpoint !~\".*pod.*\"" +
                "}" +
            ") *100/" +
            "(" +
                "node_filesystem_avail_bytes {" +
                    "instance=~\""+ LINUX_INSTANCE +"\"," +
                    "fstype=~\"ext.*|xfs\"," +
                    "mountpoint !~\".*pod.*\"" +
                "}" +
                "%2B" +
                "(" +
                    "node_filesystem_size_bytes{" +
                        "instance=~\""+ LINUX_INSTANCE +"\"," +
                        "fstype=~\"ext.*|xfs\"," +
                        "mountpoint !~\".*pod.*\"" +
                    "}-" +
                    "node_filesystem_free_bytes{" +
                        "instance=~\""+ LINUX_INSTANCE +"\"," +
                        "fstype=~\"ext.*|xfs\"," +
                        "mountpoint !~\".*pod.*\"" +
                    "}" +
                ")" +
            ")";

    /**
     * 磁盘读速率
     */
    String DISK_READ_SPEED = "irate(node_disk_reads_completed_total{instance=~\""+ LINUX_INSTANCE +"\"}[5m])";

    /**
     * 磁盘写速率
     */
    String DISK_WRITE_SPEED = "irate(node_disk_writes_completed_total{instance=~\""+ LINUX_INSTANCE +"\"}[5m])";

    /**
     * 每1秒内I&#x2F;O操作耗时占比
     */
    String SECOND_IO_PERCENTAGE = "irate(node_disk_io_time_seconds_total{instance=~\""+ LINUX_INSTANCE +"\"}[5m])";

    /**
     * 每次IO读的耗时（参考：小于100ms）(beta)
     */
    String SECOND_IO_READ_TIME = "irate(node_disk_read_time_seconds_total{instance=~\""+ LINUX_INSTANCE +"\"}[5m]) / irate(node_disk_reads_completed_total{instance=~\""+ LINUX_INSTANCE +"\"}[5m])";

    /**
     * 每次IO写耗时（参考：小于100ms）(beta)
     */
    String SECOND_IO_WRITE_TIME = "irate(node_disk_write_time_seconds_total{instance=~\""+ LINUX_INSTANCE +"\"}[5m]) / irate(node_disk_writes_completed_total{instance=~\""+ LINUX_INSTANCE +"\"}[5m])";

    /**
     *  当前建立的TCP连接数
     */
    String NET_TCP_CURR_ESTAB = "node_netstat_Tcp_CurrEstab{instance=~'"+ LINUX_INSTANCE +"'}";

    /**
     * 处于时间等待状态的TCP连接
     */
    String SOCKET_TCP_TW = "node_sockstat_TCP_tw{instance=~'"+ LINUX_INSTANCE +"'}";

    /**
     * 正在使用的socket数量
     */
    String SOCKET_USED = "node_sockstat_sockets_used{instance=~'"+ LINUX_INSTANCE +"'}";

    /**
     * 正在使用的UDP套接字数量
     */
    String SOCKET_INUSE = "node_sockstat_UDP_inuse{instance=~'"+ LINUX_INSTANCE +"'}";

    /**
     * 已分配的TCP套接字数量
     */
    String SOCKET_TCP_ALLOC = "node_sockstat_TCP_alloc{instance=~'"+ LINUX_INSTANCE +"'}";

    /**
     * TCP 接收的目前所有建立连接的错误报文数
     */
    String NET_TCP_IN_SEGS = "irate(node_netstat_Tcp_InSegs{instance=~'"+ LINUX_INSTANCE +"'}[5m])";

    /**
     * 已经发送但未被确认的TCP段数量
     */
    String NET_TCP_OUT_SEGS ="irate(node_netstat_Tcp_OutSegs{instance=~'"+ LINUX_INSTANCE +"'}[5m])";

    /**
     * 发生重传的TCP分片数量
     */
    String NET_TCP_RETRANS_SEGS = "irate(node_netstat_Tcp_RetransSegs{instance=~'"+ LINUX_INSTANCE +"'}[5m])";

    /**
     * 使用的文件描述符
     */
    String FILE_ALLOCATED = "node_filefd_allocated{instance=~\""+ LINUX_INSTANCE +"\"}";

    /**
     * 总文件描述符
     */
    String TOTAL_FILE_ALLOCATED = "avg(node_filefd_maximum{instance=~\""+ LINUX_INSTANCE +"\"})";

    /**
     * 每秒上下文切换次数
     */
    String CONTEXT_SWITCHES = "irate(node_context_switches_total{instance=~\""+ LINUX_INSTANCE +"\"}[5m])";
}
